/**
 * 初始化查询数据
 */
define(['jquery'], function ($) {
    //  设置产品分类ID
    function setCategoryId(d) {
        window.localStorage.setItem("categoryId",d);
    }

    //  获取产品分类ID
    function getCategoryId() {
        if (!!window.localStorage.getItem("categoryId") && window.localStorage.getItem("categoryId").length > 0) {
            return window.localStorage.getItem("categoryId");
        }
        return $("#categoryId").val();
    }

    //  设置当前页码
    function setPageNo(d) {
        $("#pageNo").val(d);
    }

    //  获取当前页码
    function getPageNo() {
        return $("#pageNo").val();
    }

    //  设置当前页可以显示数据数目
    function setPageSize(d) {
        window.localStorage.setItem("pageSize", d);
    }

    //  获取当前页可以显示数据数目
    function getPageSize() {
        return window.localStorage.getItem("pageSize");
    }

    // 设置查询关键字
    function setKeyword(d) {
        console.log(d)
        window.localStorage.setItem("keyword", d);
        window.localStorage.setItem("searchKeywords", d);
    }
    // 获取查询的关键字
    function getKeyword() {
        if (!!window.localStorage.getItem("searchKeywords") && window.localStorage.getItem("searchKeywords").length > 0) {
            return window.localStorage.getItem("searchKeywords");
        }
        return "";        
    }

    // 设置当前网点
    function setNetPoint(opts) {
        if (typeof opts == 'string') {
            opts = $.parseJSON(opts);
        }
        window.localStorage.setItem("netPoint", JSON.stringify(opts));
    }
    // 获取当前网点
    function getNetPoint() {
        if (!!window.localStorage.getItem("netPoint")) {
            return $.parseJSON(window.localStorage.getItem("netPoint"));
        }
        else{
            return {
                name: $("#netPointNameShow").attr("data-name"),
                id: $("#netPointNameShow").attr("data-id"),
                address: $("#netPointNameShow").attr("data-address")
            };//$("#defaultPointId").val();
        }
    }
    // 移除记录的当前网点
    function removeNetPoint() {
        window.localStorage.removeItem("netPoint");
    }
    function reset() {
        //setCategoryId($("#allCategory").attr("data-prodType"));
        setPageNo("1");
        setKeyword("");
    }
    return {
        setCategoryId: setCategoryId,
        getCategoryId: getCategoryId,
        setPageNo: setPageNo,
        getPageNo: getPageNo,
        setPageSize: setPageSize,
        getPageSize:getPageSize,
        setKeyword: setKeyword,
        getKeyword:getKeyword,
        setNetPoint:setNetPoint,
        getNetPoint:getNetPoint,
        removeNetPoint: removeNetPoint,
        reset:reset
    }

});